<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">请求数据</button>
</body>
</html>
<script>
    btn.onclick=function(){
        
        // 创建ajax对象
        let xhr=new XMLHttpRequest()

        // 建立连接
        xhr.open("get","http://localhost:3000")

        // 发送请求
        xhr.send()

        // 监听ajax请求的状态
        xhr.onreadystatechange=function(){


            // readyState为4  status为200
            if(xhr.readyState==4 && xhr.status==200){


                console.log(JSON.parse(xhr.responseText));
            }


        }


    }
</script>